import chardet
import os
import argparse

def strJudgeCode(str):
	return chardet.detect(str)

def readFile(path):
	try:
		f = open(path, 'r')
		filecontent = f.read()
	finally:
		if f:
			f.close()

	return filecontent

def WriteFile(str, path):
	try:
		f = open(path, 'w')
		f.write(str)
	finally:
		if f:
			f.close()

def printCode(path):
	file_con = readFile(path)
	result = strJudgeCode(file_con)
	print(result['encoding'])

if __name__ == '__main__':
	parser = argparse.ArgumentParser(description = 'print string\'s code')
	parser.add_argument('-f', help="please input file name")
	args = parser.parse_args()

	printCode(args.f)